#define _CRT_SECURE_NO_WARNINGS
//////////////////////1
class Solution {
public:
    int findTargetSumWays(vector<int>& nums, int target) {
        int sum = 0, n = nums.size();
        for (auto& e : nums) sum += e;
        int aim = (sum + target) / 2;
        if (aim < 0 || (sum + target) % 2 == 1) return 0;
        vector<vector<int>> dp(n + 1, vector<int>(aim + 1, 0));
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++)
            for (int j = 0; j <= aim; j++) {
                dp[i][j] = dp[i - 1][j];
                if (j >= nums[i - 1]) dp[i][j] = dp[i][j] + dp[i - 1][j - nums[i - 1]];
            }
        return dp[n][aim];
    }
};
//////////////////////1

//////////////////////2
class Solution {
public:
    int findTargetSumWays(vector<int>& nums, int target) {
        int sum = 0, n = nums.size();
        for (auto& e : nums) sum += e;
        int aim = (sum + target) / 2;
        if (aim < 0 || (sum + target) % 2 == 1) return 0;
        vector<int> dp(aim + 1, 0);
        dp[0] = 1;
        for (int i = 1; i <= n; i++)
            for (int j = aim; j >= nums[i - 1]; j--) {
                dp[j] = dp[j] + dp[j - nums[i - 1]];
            }
        return dp[aim];
    }
};
//////////////////////2